<?php
// +----------------------------------------------------------------------
// | Description: restFul风格 api接口基础类
// +----------------------------------------------------------------------
// | Author: dongpeng
// +----------------------------------------------------------------------

namespace App\Common\Controller;

class Rest extends Common
{
    public function GETIndex()
    {
        if(isset($this->param['Id'])){
            $res = $this->model()->getDataById($this->param['Id']); 
        }else{
            $res = $this->model()->getDataList($this->param);
        }
        $this->result($res, ['msg' => self::$model->getError(), 'data' => $res]);
    }

    public function POSTIndex()
    {
        $res = $this->model()->createData($this->param);
        $this->result($res, ['msg' => self::$model->getError()]);
    }

    public function PUTIndex()
    {
        $res = $this->model()->updateDataById($this->param, $this->param['Id']);
        $this->result($res, ['msg' => self::$model->getError()]);
    }

    public function DELETEIndex()
    {
        $res = $this->model()->delDataById($this->param['Id']);
        $this->result($res, ['msg' => self::$model->getError()]);
    }

    public function POSTDeletes()
    {
        // echo 'deletes';
        $res = $this->model()->delDatas($this->param['ids']);
        $this->result($res, ['msg' => self::$model->getError()]);
    }

    public function POSTEnables()
    {
        $res = $this->model()->enableDatas($this->param['ids'], $this->param['status']);
        $this->result($res, ['msg' => self::$model->getError()]);
    }
}
